using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace PowerShellConsole
{
    class PowershellScript : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = (SPSite)properties.Feature.Parent;
            SPList scriptsList = null;
            try
            {
                scriptsList = site.RootWeb.Lists["PowershellScripts"];
            }
            catch { }
            if (scriptsList == null)
            {
                Guid listId = site.RootWeb.Lists.Add("PowershellScripts", "Stores Powershell Scripts", SPListTemplateType.DocumentLibrary);
                scriptsList = site.RootWeb.Lists[listId];
                scriptsList.ContentTypes.Add(site.RootWeb.ContentTypes["PowershellScript"]);
                scriptsList.ContentTypes.Delete(scriptsList.ContentTypes["Document"].Id);
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = (SPSite)properties.Feature.Parent;
            SPList scriptsList = null;
            try
            {
                scriptsList = site.RootWeb.Lists["PowershellScripts"];
            }
            catch { }
            if (scriptsList != null)
            {
                scriptsList.Delete();
            }
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            
        }
    }
}
